{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "--------\n",
    "\n",
    "* 本学习记录人：许智超\n",
    "* 学习时间：2021-12-14\n",
    "* week16\n",
    "* 参考的文档：\n",
    "> 1. [python官方文档](https://python.org/doc)\n",
    "> 2. [许老师博客](https://cnblogs.com/xuzhichao)\n",
    "\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 本周知识点\n",
    "\n",
    "### 1. Flask搭建web应用-实现hello world\n",
    "> 1. 安装配置flask（pip install flask）\n",
    "> 2. [Flask官方文档](https://dormousehole.readthedocs.io/en/latest/)\n",
    "> 3.  central registry (中央登记处)\n",
    ">> 1. 登记服务端的 路由: 决定了url地址的 终结点（endpoint）\n",
    "\n",
    ">> 2. 登记服务端的 功能代码（视图函数）\n",
    "\n",
    "\n",
    "### 2. flask 实践一个小项目"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help(Flask)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "* Request（用户）\n",
    "> 1. GET请求 ---> 服务端做出的 Response（服务端） 响应（回应）\n",
    "> 2. 前后端分离：模板渲染，有一个template文件夹，专门放页面的数据文件的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: Do not use the development server in a production environment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /cms/web/writeLog.jsp?siteID=bbef6bf928be491d9180b44993df0ac9&channelID=e00ade4e79954ba58847e6733f415e75&contentID=$curArticle.id HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /js/jquery.nivo.slider.pack.js HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /js/scroll.js HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /g_style/g_index.js HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-04/17e7b8517fe94672a817273446ef58ff.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-04/28879d910a044415b331128fd5b00257.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-11/d61cec029af94ab382e65161f02a3537.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-06/c4dc230ec1db48c1811ce5f36acba7c5.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-06/88b78547776d4d2faca8000e91c4e98f.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-03/a54727640194468bb27ef66826656bdc.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-03/f71dece32bea463e8f072b6a394443a0.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/20c9167fd8294c11b85b469de8f6b78e.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/6b4e0029642544d685721fef2c0e6982.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/34a1a12738c44d27a85311a99a732d40.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/a03edb0c8bc149e5bd5cfaba65fdadcd.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /cms/web/writeLog.jsp?siteID=bbef6bf928be491d9180b44993df0ac9&channelID=e00ade4e79954ba58847e6733f415e75&contentID=$curArticle.id HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/3b21c8b517844515a47b3c85b0295911.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /js/jquery.nivo.slider.pack.js HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/2021-12/1e61881d3945477ab571637d13e7dd3d.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/5a0a625edc056.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/576b2e290db81.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/5a0c1b7e6621e.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/5a0a56b7de064.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/5a12a21f9e764.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /js/scroll.js HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/erweima1.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/erweima2.jpg HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /images/icp.png HTTP/1.1\" 404 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:33:49] \"GET /g_style/g_index.js HTTP/1.1\" 404 -\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route(\"/\")\n",
    "# / 指的是 根路径，首页，域名直接指向的网页\n",
    "def hello_world():\n",
    "    return render_template(\"flask_index.html\")\n",
    "\n",
    "@app.route(\"/log\")\n",
    "def log_page():\n",
    "    return \"<h1>这是日志页</h1>\"\n",
    "\n",
    "@app.route(\"/me\")\n",
    "def me_page():\n",
    "    return \"<h1>这是个人中心</h1>\"\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "### 2. flask 实践一个小项目\n",
    "> 1. full_name\n",
    "> 2. 一个真正的应用，用户是不能写代码的！！\n",
    "> 3. [html表单](https://www.w3school.com.cn/html/html_forms.asp)用于收集用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: Do not use the development server in a production environment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [14/Dec/2021 11:54:20] \"GET / HTTP/1.1\" 200 -\n",
      "127.0.0.1 - - [14/Dec/2021 11:54:29] \"GET /?firstname=Li&lastname=Hua HTTP/1.1\" 200 -\n"
     ]
    }
   ],
   "source": [
    "# 实践2\n",
    "from flask import Flask\n",
    "from flask import render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route(\"/\")\n",
    "# / 指的是 根路径，首页，域名直接指向的网页\n",
    "def index():\n",
    "    return render_template(\"index.html\")\n",
    "\n",
    "@app.route(\"/result\")\n",
    "def result():\n",
    "    return render_template(\"result.html\")\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 思考和作业\n",
    "\n",
    "> 1. 实践2请大家完成\n",
    "> 2. 思考：如何把数据传递给python的代码中（阅读课本第五章，答案便可揭晓）\n",
    "> 3. 作业：课本第五章实践练习，尝试提前完成\n",
    "\n",
    "### 期末项目\n",
    "\n",
    "> 核心目标： flask 项目 实现 用户输入的结果我们可以操作后返回（课程表、购物车、猜数字小游戏、天气应用（老师带大家做））"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
